package com.wish.business.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @ClassName:
 * @Description:
 *
 * @Date:2022/1/17 19:12
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AjaxResult implements Serializable {

    //ajax接口是否正常相应
    private boolean result;
    //接口返回数据
    private Object data;
    //错误编码
    private int errCode;
    //错误提示
    private String message;

    /**
     * 正常消息返回
     * @return
     */
    public static AjaxResult ok(){
        return new AjaxResult(true, null, 0, null);
    }

    public static AjaxResult ok(Object data){
        return new AjaxResult(true, data, 0, null);
    }


    /**
     * 错误相应
     * @return
     */
    public static AjaxResult err(){
        return new AjaxResult(false, null, 0, null);
    }

    public static AjaxResult err(Integer errCode,String message){
        return new AjaxResult(false, null, errCode, message);
    }

   /* @RequestMapping("/login")
    public Map<String, Object> login(String name, String password){
        HashMap<String, Object> map = new HashMap<>();
        byte key[] =  "123456".getBytes();
        String token = "";
        if(name.equals("admin") && password.equals("123")){
            token = JWT.create()
                    .setPayload("name", name)
                    .setPayload("pasword", password)
                    .setKey(key).sign();
            map.put("token",token);
        }
        return map;
    }*/
  /* @RequestMapping("cityList")
   public AjaxResult cityList(){
       List<City> list = cityService.list();
       TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
       treeNodeConfig.setIdKey("id");
       treeNodeConfig.setParentIdKey("pid");
       treeNodeConfig.setNameKey("cityName");
       treeNodeConfig.setChildrenKey("children");

       treeNodeConfig.setDeep(3);

       List<Tree<Integer>> treeList = TreeUtil.build(list, 1, treeNodeConfig, (city, treeNode) -> {
           treeNode.setId(city.getId());
           treeNode.setParentId(city.getPid());
           treeNode.setName(city.getName());
           treeNode.putExtra("label", city.getName());
       });
       System.out.println(treeList);
       return AjaxResult.ok(treeList);
   }*/
}
